<%@ include file="/common/taglibs.jsp"%>
<title><fmt:message key="approve2.title"/></title>
<%
response.setHeader("Cache-Control","no-cache"); // HTTP 1.1
response.setHeader("Pragma","no-cache"); // HTTP 1.0
response.setHeader("Cache-Control", "no-cache,no-store,must-revalidate");
response.setDateHeader ("Expires", -1); // Prevents caching at the proxy server
%>
<script language="JavaScript" type="text/javascript">
function useExistingBusiness(){
	document.actionItems.existingBusiness.value=true;
}

function enterNewBusiness(){
	document.actionItems.existingBusiness.value=false;
}

function useBusiness(clicked){
    var form = clicked.form;
    var checkboxes = form.elements[clicked.name];
    if (!clicked.checked || !checkboxes.length) {
        clicked.parentNode.parentNode.className="";
        return false;
    }

    for (i=0; i<checkboxes.length; i++) {
        if (checkboxes[i] != clicked) {
            checkboxes[i].checked=false;
            //checkboxes[i].parentNode.parentNode.className="";
        }
    }
    document.actionItems.businessId.value=checked.value;
}
</script> 
<spring:bind path="associatorView.*">
    <c:if test="${not empty status.errorMessages}">
    <div class="error">
        <c:forEach var="error" items="${status.errorMessages}">
            <img src="<c:url value="/images/iconWarning.gif"/>"
                alt="<fmt:message key="icon.warning"/>" class="icon"/>
            <c:out value="${error}" escapeXml="false"/><br />
        </c:forEach>
    </div>
    </c:if>
</spring:bind>
<%-- set as a variable so the buttons can be used at the top and bottom of the form --%>
<c:set var="buttons">
	<input type="submit" class="button" name="_target3" value="<fmt:message key="button.submit.business"/>" onclick="useExistingBusiness()"/>
	<input type="submit" class="button" name="_target0" value="<fmt:message key="button.step1"/>"/>
    <input type="submit" class="button" name="_target2" value="<fmt:message key="button.expand.search"/>"/>
    <input type="submit" class="button" name="_target3" value="<fmt:message key="button.submit.new.establishment"/>" onclick="enterNewBusiness()"/>
    <input type="submit" class="button" name="_cancel" value="<fmt:message key="button.cancel"/>"/>
    
</c:set>
<label><fmt:message key="approve2.text"/></label><br>
<fieldset>
<legend><fmt:message key="approve1.business.details"/></legend>
<%@ include file="initialBusinessTable.inc"%>
</fieldset>
<hr class="hrGray"/>
<fieldset>
<legend><fmt:message key="approve2.matching.business"/></legend>
<form:form name="actionItems" commandName="associatorView" method="post" action="/wems/associateComplaint2.html?tab=pendingComplaints" onsubmit="return validateBusiness(this)">
<input type="hidden" name="page" value="1" />
<input type="hidden" name="existingBusiness" value="false"/>
<display:table name="sessionScope.businessList" class="capacitytable" requestURI="" id="businessList" export="false">
    <display:column titleKey="business.check" class="nosort" sortable="false" media="html">
      <input id="businessId" name="businessId" type="checkbox" value="<c:out value='${businessList.businessId }'/>" onclick="useBusiness(this);"/>
    </display:column>
    <display:column property="businessName" titleKey="business.name" sortable="false" media="html"/>
    <display:column property="businessAddress1" titleKey="business.address" sortable="false" media="html"/>
    <display:column property="businessCity" titleKey="business.city" sortable="false" media="html"/>
    <display:column property="businessZip" titleKey="business.zip" sortable="false" media="html"/>
    <display:column property="businessPhone" titleKey="business.phone" sortable="false" media="html" />
    <display:column property="businessPhoneExt" titleKey="business.phone.ext" sortable="false" media="html" />
</display:table>
<script type="text/javascript">highlightTableRows("businessList");</script>
<table border="0" width="100%">
<tr>
	<td>&nbsp;</td>
</tr>
<tr>
	<td class="buttonBar" colspan="2" align="center">
    <c:out value="${buttons}" escapeXml="false"/>
    
	</td>
</tr>
</table>	
</form:form>
</fieldset>
